import pinyin from 'js-pinyin';
import type { SelectOptionData } from '@arco-design/web-vue/es/select/interface';

// 移除空数组
export const removeEmptyChild = (tree: any[]) => {
    for (let i = 0; i < tree.length; i++) {
        if (!tree[i].children || tree[i].children.length == 0) {
            delete tree[i].children
        } else {
            removeEmptyChild(tree[i].children);
        }
    }
}

// 过滤数据 适用 a-select :filter-option="filterOption"
export const filterOption = (input: string, option: SelectOptionData) => {
    let text: any = option.label;
    let text1 = pinyin.getFullChars(text).toLowerCase();
    let text2 = pinyin.getCamelChars(text).toLowerCase();
    let input1 = pinyin.getFullChars(input).toLowerCase();
    let input2 = pinyin.getCamelChars(input).toLowerCase();
    return text1.indexOf(input1) >= 0 || text2.indexOf(input2) >= 0;
  };
